﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace QQ群成员获取.Common
{
    public class MultiValueConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = values[0].ToString();
            string strCount = values[1].ToString();
            bool bAll = (bool)values[2];
            bool bSelect = (bool)values[3];
            string strRtn = "";
            if (bSelect == false)
            {
                strRtn = strValue;
                if (strRtn.Length > 20)
                {
                    return strRtn.Substring(0, 17) + "...";
                }
            }
            else {
                if (bAll)
                {
                    strRtn = $"{strValue}(共{strCount}人)";
                }
                strRtn = $"{strValue}(已加载{strCount}人)";
            }
            int maxLen = 18;
            if (strRtn.Length <= maxLen)
            {
                return strRtn;
            }
            int idx = strRtn.LastIndexOf('(');
            int iOtherlen = strRtn.Length - idx;
            int iremain = maxLen - iOtherlen;
            return strValue.Substring(0, iremain - 1) + "..."+ strRtn.Substring(idx,iOtherlen);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
